﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary;
using BCNPCObject;
using BCNPCObject.DB;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Forms;

namespace bus_TienichNPC
{
    public class cls_NPC_TRTH_KHANG
    {
        #region   Atributes

        private cls_NPC_TRTH_KHANG_Controller obj_NPC_TRTH_KHANG_Controller;
        private NPC_TRTH_KHANG obj_NPC_TRTH_KHANG_Info;

        #endregion


        #region   Constructor

        
        public cls_NPC_TRTH_KHANG()
        {
            obj_NPC_TRTH_KHANG_Info = new NPC_TRTH_KHANG();
            obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
        }
        public cls_NPC_TRTH_KHANG(DataSet entity)
        {
            obj_NPC_TRTH_KHANG_Info = new NPC_TRTH_KHANG();
            obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
        }       

        #endregion

        #region Method

        public DataSet select_NPC_TRTH_KHANG_All(string strMadviqly)
        {
            try
            {
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }

                var q = from p in obj_NPC_TRTH_KHANG_Controller.select_NPC_TRTH_KHANG_All(strMadviqly)
                        select new
                        {
                            p.ID_TRTH,
                            p.MA_DVIQLY,
                            p.TEN_DDIEN1,
                            p.CVU_DDIEN1,
                            p.TEN_DDIEN2,
                            p.CVU_DDIEN2,
                            p.TEN_DDIEN3,
                            p.CVU_DDIEN3,
                            p.MA_KHANG,
                            p.TEN_KHANG,
                            p.DIA_CHI,
                            p.NGUOI_TAO,
                            p.NGAY_TAO,
                            p.DDIEN_MUA,
                            p.CVU_MUA,
                            p.NGUYEN_NHAN,
                            p.LOAI_KHANG,
                            p.DCHI_TTOAN,
                            p.LOAI_CTO,
                            p.NGAY_KDINH,
                            p.CAN_CU,
                            p.DDIEN_MUA2,
                            p.CVU_MUA2,
                            p.HS_COSFI,
                            p.KCOSFI
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_KHANG";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }

                return null;
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_NPC_TRTH_KHANG_by_id_truythu(long intID)
        {
            try
            {
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }

                var q = from p in obj_NPC_TRTH_KHANG_Controller.select_NPC_TRTH_KHANG_by_id_truythu(intID)
                        select new 
                        {
                            p.ID_TRTH,
                            p.MA_DVIQLY,
                            p.TEN_DDIEN1,
                            p.CVU_DDIEN1,
                            p.TEN_DDIEN2,
                            p.CVU_DDIEN2,
                            p.TEN_DDIEN3,
                            p.CVU_DDIEN3,
                            p.MA_KHANG,
                            p.TEN_KHANG,
                            p.DIA_CHI,
                            p.NGUOI_TAO,
                            p.NGAY_TAO,
                            p.DDIEN_MUA,
                            p.CVU_MUA,
                            p.NGUYEN_NHAN,
                            p.LOAI_KHANG,
                            p.DCHI_TTOAN,
                            p.LOAI_CTO,
                            p.NGAY_KDINH,
                            p.CAN_CU,
                            p.DDIEN_MUA2,
                            p.CVU_MUA2,
                            p.HS_COSFI,
                            p.KCOSFI
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_KHANG";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }

                return null;
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_NPC_TRTH_KHANG_by_Ma_khang(string strMa_khang)
        {
            try
            {
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }

                var q = from p in obj_NPC_TRTH_KHANG_Controller.select_NPC_TRTH_KHANG_by_Ma_khang(strMa_khang)
                        select new 
                            {
                                p.ID_TRTH,
                                p.MA_DVIQLY,
                                p.TEN_DDIEN1,
                                p.CVU_DDIEN1,
                                p.TEN_DDIEN2,
                                p.CVU_DDIEN2,
                                p.TEN_DDIEN3,
                                p.CVU_DDIEN3,
                                p.MA_KHANG,
                                p.TEN_KHANG,
                                p.DIA_CHI,
                                p.NGUOI_TAO,
                                p.NGAY_TAO,
                                p.DDIEN_MUA,
                                p.CVU_MUA,
                                p.NGUYEN_NHAN,
                                p.LOAI_KHANG,
                                p.DCHI_TTOAN,
                                p.LOAI_CTO,
                                p.NGAY_KDINH,
                                p.CAN_CU,
                                p.DDIEN_MUA2,
                                p.CVU_MUA2,
                                p.HS_COSFI,
                                p.KCOSFI
                            };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_KHANG";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }

                return null;
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_NPC_TRTH_KHANG_by_1_Col_co(DataSet Entity)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                var q = from p in obj_NPC_TRTH_KHANG_Controller.select_NPC_TRTH_KHANG_by_1_Col_co()
                        select new 
                        {
                            p.ID_TRTH,
                            p.MA_DVIQLY,
                            p.TEN_DDIEN1,
                            p.CVU_DDIEN1,
                            p.TEN_DDIEN2,
                            p.CVU_DDIEN2,
                            p.TEN_DDIEN3,
                            p.CVU_DDIEN3,
                            p.MA_KHANG,
                            p.TEN_KHANG,
                            p.DIA_CHI,
                            p.NGUOI_TAO,
                            p.NGAY_TAO,
                            p.DDIEN_MUA,
                            p.CVU_MUA,
                            p.NGUYEN_NHAN,
                            p.LOAI_KHANG,
                            p.DCHI_TTOAN,
                            p.LOAI_CTO,
                            p.NGAY_KDINH,
                            p.CAN_CU,
                            p.DDIEN_MUA2,
                            p.CVU_MUA2,
                            p.HS_COSFI,
                            p.KCOSFI
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_KHANG";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }

        }

        public DataSet select_NPC_TRTH_KHANG_by_1_Col_dtu(DataSet Entity)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                var q = from p in obj_NPC_TRTH_KHANG_Controller.select_NPC_TRTH_KHANG_by_1_Col_dtu()
                        select new
                        {
                            p.ID_TRTH,
                            p.MA_DVIQLY,
                            p.TEN_DDIEN1,
                            p.CVU_DDIEN1,
                            p.TEN_DDIEN2,
                            p.CVU_DDIEN2,
                            p.TEN_DDIEN3,
                            p.CVU_DDIEN3,
                            p.MA_KHANG,
                            p.TEN_KHANG,
                            p.DIA_CHI,
                            p.NGUOI_TAO,
                            p.NGAY_TAO,
                            p.DDIEN_MUA,
                            p.CVU_MUA,
                            p.NGUYEN_NHAN,
                            p.LOAI_KHANG,
                            p.DCHI_TTOAN,
                            p.LOAI_CTO,
                            p.NGAY_KDINH,
                            p.CAN_CU,
                            p.DDIEN_MUA2,
                            p.CVU_MUA2,
                            p.HS_COSFI,
                            p.KCOSFI
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_KHANG";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }

        }

        public bool insert_NPC_TRTH_KHANG(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }
                return obj_NPC_TRTH_KHANG_Controller.insert_NPC_TRTH_KHANG(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }
        }

        public bool update_NPC_TRTH_KHANG(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }
                return this.obj_NPC_TRTH_KHANG_Controller.update_NPC_TRTH_KHANG(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }

        }

        public bool delete_NPC_TRTH_KHANG(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }
                return this.obj_NPC_TRTH_KHANG_Controller.delete_NPC_TRTH_KHANG(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }
        }

        public long GetNextSEQ_NPC_TRUYTHU(ref string strErr)
        {
            try
            {
                if (obj_NPC_TRTH_KHANG_Controller == null)
                {
                    obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
                }

                long id = obj_NPC_TRTH_KHANG_Controller.GetNextSEQ_NPC_TRUYTHU(ref strErr);
                return id;
            }
            catch
            {
                return -1;
            }
        }

        public void mapEntityToInfo(DataSet Entity)
        {
            if (this.obj_NPC_TRTH_KHANG_Controller == null)
            {
                this.obj_NPC_TRTH_KHANG_Controller = new cls_NPC_TRTH_KHANG_Controller();
            }
            if (Entity.Tables[0].Rows[0]["ID_TRTH"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.ID_TRTH = Convert.ToInt64(Entity.Tables[0].Rows[0]["ID_TRTH"]);
            }
            
            this.obj_NPC_TRTH_KHANG_Controller.pInfor.MA_DVIQLY = Entity.Tables[0].Rows[0]["MA_DVIQLY"].ToString();
            this.obj_NPC_TRTH_KHANG_Controller.pInfor.TEN_DDIEN1 = Entity.Tables[0].Rows[0]["TEN_DDIEN1"].ToString();
            this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_DDIEN1 = Entity.Tables[0].Rows[0]["CVU_DDIEN1"].ToString();

            if (Entity.Tables[0].Rows[0]["TEN_DDIEN2"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.TEN_DDIEN2 = Entity.Tables[0].Rows[0]["TEN_DDIEN2"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.TEN_DDIEN2 = null;
            }

            if (Entity.Tables[0].Rows[0]["CVU_DDIEN2"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_DDIEN2 = Entity.Tables[0].Rows[0]["CVU_DDIEN2"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_DDIEN2 = null;
            }

            if (Entity.Tables[0].Rows[0]["TEN_DDIEN3"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.TEN_DDIEN3 = Entity.Tables[0].Rows[0]["TEN_DDIEN3"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.TEN_DDIEN3 = null;
            }

            if (Entity.Tables[0].Rows[0]["CVU_DDIEN3"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_DDIEN3 = Entity.Tables[0].Rows[0]["CVU_DDIEN3"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_DDIEN3 = null;
            }

            if (Entity.Tables[0].Rows[0]["MA_KHANG"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.MA_KHANG = Entity.Tables[0].Rows[0]["MA_KHANG"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.MA_KHANG = null;
            }

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.TEN_KHANG = Entity.Tables[0].Rows[0]["TEN_KHANG"].ToString();

            if (Entity.Tables[0].Rows[0]["DIA_CHI"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.DIA_CHI = Entity.Tables[0].Rows[0]["DIA_CHI"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.DIA_CHI = null;
            }

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.NGUOI_TAO = Entity.Tables[0].Rows[0]["NGUOI_TAO"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.NGAY_TAO = Convert.ToDateTime(Entity.Tables[0].Rows[0]["NGAY_TAO"]);

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.DDIEN_MUA = Entity.Tables[0].Rows[0]["DDIEN_MUA"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_MUA = Entity.Tables[0].Rows[0]["CVU_MUA"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.NGUYEN_NHAN = Entity.Tables[0].Rows[0]["NGUYEN_NHAN"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.LOAI_KHANG = Entity.Tables[0].Rows[0]["LOAI_KHANG"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.DCHI_TTOAN = Entity.Tables[0].Rows[0]["DCHI_TTOAN"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.LOAI_CTO = Entity.Tables[0].Rows[0]["LOAI_CTO"].ToString();

            this.obj_NPC_TRTH_KHANG_Controller.pInfor.NGAY_KDINH = Convert.ToDateTime(Entity.Tables[0].Rows[0]["NGAY_KDINH"]);

            if (Entity.Tables[0].Rows[0]["CAN_CU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CAN_CU = Entity.Tables[0].Rows[0]["CAN_CU"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CAN_CU = null;
            }

            if (Entity.Tables[0].Rows[0]["DDIEN_MUA2"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.DDIEN_MUA2 = Entity.Tables[0].Rows[0]["DDIEN_MUA2"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.DDIEN_MUA2 = null;
            }

            if (Entity.Tables[0].Rows[0]["CVU_MUA2"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_MUA2 = Entity.Tables[0].Rows[0]["CVU_MUA2"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.CVU_MUA2 = null;
            }

            if (Entity.Tables[0].Rows[0]["HS_COSFI"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.HS_COSFI = Convert.ToDecimal(Entity.Tables[0].Rows[0]["HS_COSFI"]);
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.HS_COSFI = null;
            }

            if (Entity.Tables[0].Rows[0]["KCOSFI"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.KCOSFI = Convert.ToDecimal(Entity.Tables[0].Rows[0]["KCOSFI"]);
            }
            else
            {
                this.obj_NPC_TRTH_KHANG_Controller.pInfor.KCOSFI = null;
            }
        }

        #endregion
    }
}
